package month1;

public class MinStack155_08 {

    /**
     * 链栈
     */
    static class MinStack {
        static class Node {
            Node next;
            int min, val;

            Node() {
            }

            Node(Node next, int val, int min) {
                this.next = next;
                this.val = val;
                this.min = min;
            }
        }

        Node head;

        public MinStack() {
            head = new Node();
            head.min = Integer.MAX_VALUE;
        }

        public void push(int val) {
            head = new Node(head, val, Math.min(val, head.min));
        }

        public void pop() {
            head = head.next;
        }

        public int top() {
            return head.val;
        }

        public int getMin() {
            return head.min;
        }
    }
}
